import {DXMResponse} from "./common";
import { invoke } from "@tauri-apps/api/core";
const dxc_name = "EcommerceDataAnalysisService"
const dxc_version = "0.0.1"
export type MonthlyRegister = { 
  month: number, 
  num: number, 
}
export type MonthlyVolume = { 
  month: number, 
  volume: number, 
}
export type ProductVolumeShare = { 
  category: string, 
  share: number, 
}
export type ProductRevenuShare = { 
  category: string, 
  share: number, 
}
export type UserActiveData = { 
  online_num: number, 
  monthly_active_datas: Array<MonthlyActive>, 
  hour_active_datas: Array<HourActive>, 
}
export type HourActive = { 
  segment: number, 
  num: number, 
}
export type MonthlyActive = { 
  month: number, 
  num: number, 
}
export type DataRequest = { 
  year: number, 
}
export type MonthlyRevenu = { 
  month: number, 
  revenu: number, 
}
export type ProductSaleData = { 
  revenu: number, 
  volume: number, 
  monthly_revenu_datas: Array<MonthlyRevenu>, 
  monthly_volume_datas: Array<MonthlyVolume>, 
  product_revenu_share_datas: Array<ProductRevenuShare>, 
  product_volume_share_datas: Array<ProductVolumeShare>, 
}
export type UserRegisterData = { 
  total_num: number, 
  monthly_register_datas: Array<MonthlyRegister>, 
}
export async function SubscribeData () { 
    const ret = await invoke("invoke_dxc", {
            invokeRequest: {
              dxc_name,
              dxc_version,
              api: "SubscribeData",
              params: {}
            }
  });
  return ret as DXMResponse<{}>;
} 

export async function GetProductData (param: DataRequest) { 
    const ret = await invoke("invoke_dxc", {
            invokeRequest: {
              dxc_name,
              dxc_version,
              api: "GetProductData",
              params: param
            }
  });
  return ret as DXMResponse<ProductSaleData>;
} 

export async function GetUserRegisterData (param: DataRequest) { 
    const ret = await invoke("invoke_dxc", {
            invokeRequest: {
              dxc_name,
              dxc_version,
              api: "GetUserRegisterData",
              params: param
            }
  });
  return ret as DXMResponse<UserRegisterData>;
} 

export async function GetUserActiveData (param: DataRequest) { 
    const ret = await invoke("invoke_dxc", {
            invokeRequest: {
              dxc_name,
              dxc_version,
              api: "GetUserActiveData",
              params: param
            }
  });
  return ret as DXMResponse<UserActiveData>;
} 

